package com.info.controller;

import com.info.bll.UserBLL;
import com.info.dal.UserDAL;
import com.info.model.UserInfo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "registerServlet", value = "/registerServlet")
public class registerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //注册功能
        //封装用户对象，将用户输入的用户名和密码设置在用户对象中
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(request.getParameter("username"));
        userInfo.setUserpass(request.getParameter("userpass"));

        UserBLL userBLL = new UserBLL();
        if(userBLL.addUser(userInfo)){
            //添加成功
            //跳转登录
            response.sendRedirect("login.jsp");
        }else{
            //添加失败
            response.sendRedirect("register.jsp");
        }
    }
}
